package com.xy.user.service.impl;

import com.ruoyi.common.core.domain.user.Employee;
import com.ruoyi.common.core.mapper.user.EmployeeSkillMapper;
import com.xy.user.service.EmployeeSkillService;
import com.xy.user.service.ISkillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class EmployeeSkillServiceImpl implements EmployeeSkillService {
    @Autowired
    private EmployeeSkillMapper employeeSkillMapper;
    @Autowired
    private ISkillService skillService;

    /**
     * 查询员工信息(根据员工编号)
     *
     * @param id 员工ID
     * @return
     */
    @Override
    public Employee getEmployeeWithSkills(String id) {
        return employeeSkillMapper.getSkillsByEmployeeId(id);
    }


    /**
     * 查询所有员工信息
     */
    @Override
    public List<Employee> getAllEmployees(Employee employee) {
        List<Employee> list;
        String skills = employee.getSkills();

        if (skills != null) {
            String[] split = skills.split(",");
            list = employeeSkillMapper.getListBySkills(
                    split,
                    employee.getName(),
                    employee.getServiceArea(),
                    employee.getAvgRating(),
                    employee.getAge(),
                    employee.getGender(),
                    employee.getPhone(),
                    employee.getExperience(),
                    employee.getEmploymentStatus());
        } else {
            list = employeeSkillMapper.getList(
                    employee.getName(),
                    employee.getServiceArea(),
                    employee.getAvgRating(),
                    employee.getAge(),
                    employee.getGender(),
                    employee.getPhone(),
                    employee.getExperience(),
                    employee.getEmploymentStatus());
        }

        return list == null ? null : list.stream()
                .peek(e -> e.setSkillList(skillService.getSkill(e.getSkills())))
                .collect(Collectors.toList());
    }
}